package dabs.ginterface;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import dabs.engine.control.ComponentCommand;
import dabs.engine.control.GameCommand;
import dabs.engine.control.ReadCommand;

public class ParserTester {

	CommandParser parser;
	
	@Before
	public void setUp() throws Exception {
		parser = new CommandParser();
	}

	@Test
	public void testReadCommand() {
		ReadCommand gc = (ReadCommand)(parser.asReadCommand("read reactor1 pressure"));
		assertEquals(gc.getDestination(), "reactor1");
		assertEquals(gc.getAttribute(), "pressure");
	}
	
	@Test
	public void testGameCommand() {
		GameCommand gc = (GameCommand)(parser.asGameCommand("save"));
		assertEquals(gc.toString(), "save");
	}
	
	@Test
	public void testComponentCommand() {
		ComponentCommand gc = (ComponentCommand)(parser.asComponentCommand("reactor1 rod raise 100"));
		assertEquals(gc.getDestination(), "reactor1");
		
		System.out.println(gc.getArguments());
		
		assertEquals(gc.getArguments().get(0), "rod");
		assertEquals(gc.getArguments().get(1), "raise");
		assertEquals(gc.getArguments().get(2), "100");
	}
	
	@Test
	public void testEnoughPlayingAround() {
		
		// assertEquals(parser.type(""), "");
		assertEquals(parser.type("reactor1"), "");
		assertEquals(parser.type("quit"), "gamecommand");
		assertEquals(parser.type("read"), "");
		assertEquals(parser.type("read valve1"), "");
		assertEquals(parser.type("read valve2 something"), "read");
		assertEquals(parser.type("print list"), "");
		assertEquals(parser.type("something something else"), "");
		assertEquals(parser.type("valve2 open"), "componentcommand");
		assertEquals(parser.type("valve3 close 100"), "componentcommand");
		assertEquals(parser.type("valve sth sth"), "");
		assertEquals(parser.type("reactor sth"), "");
		assertEquals(parser.type("consenser stop"), "");
		
	}

}
